class CoolBtnContent extends egret.Sprite
{
	public constructor(texture:egret.Texture,callback:Function,callbackObj:egret.DisplayObjectContainer) 
	{
		super();
		this.init(texture,callback,callbackObj);
	}
	private m_Callback:Function;
	private m_CallbackObj:egret.DisplayObjectContainer;
	private m_touchBegin:boolean = false;
	public init(texture:egret.Texture,callback:Function,callbackObj:egret.DisplayObjectContainer)
	{
		this.m_CallbackObj = callbackObj;
		this.m_Callback = callback;
		this.width = texture.textureWidth;
        this.height = texture.textureHeight;
		this.anchorOffsetX = this.width / 2;
		this.anchorOffsetY = this.height / 2;
		this.touchEnabled = true;
		this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.touchBegin, this);
		this.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.touchMoved, this);
		this.addEventListener(egret.TouchEvent.TOUCH_END, this.touchEnd, this);
		this.addEventListener(egret.TouchEvent.TOUCH_RELEASE_OUTSIDE, this.touchCancel, this);
		this.addEventListener(egret.TouchEvent.TOUCH_CANCEL, this.touchCancel, this);
	}
    public drawCircle(color:number, radium:number = this.width / 2)
    {
        this.graphics.beginFill(color);
        this.graphics.drawCircle(this.width / 2, this.height / 2, radium);
		this.graphics.endFill();

		this.graphics.lineStyle(4, 0xffffff);
		this.graphics.drawArc(this.width / 2,this.height / 2, radium, 0, Math.PI * 2, false);
		this.graphics.endFill();

		// this.graphics.lineStyle(3, 0x000000);
		// this.graphics.drawArc(this.width / 2,this.height / 2, radium + 2, 0, Math.PI * 2, false);
		// this.graphics.endFill();
    }
	private touchBegin(event:egret.TouchEvent)
	{
		this.m_touchBegin = true;
		this.scaleX = 1.1;
		this.scaleY = 1.1;
	}
	private touchMoved(event:egret.TouchEvent)
	{
		//console.log("moved");
	}
	private touchEnd(event:egret.TouchEvent)
	{
		this.scaleX = 1.0;
		this.scaleY = 1.0;
		if(this.m_Callback != null && this.m_touchBegin)
		{
			this.m_touchBegin = false;
			let bindFunction = this.m_Callback.bind(this.m_CallbackObj);
			bindFunction(event);
		}
	}
	private touchCancel(event:egret.TouchEvent)
	{
		this.m_touchBegin = false;
		this.scaleX = 1.0;
		this.scaleY = 1.0;
	}
}